/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Common;

import Views.*;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import org.jfree.ui.RefineryUtilities;

/**
 *
 * @author TrongChien
 */
public class FileMenu implements ActionListener {

    public String userId;
    Bills b;
    public MainForm mainForm = null;

    public FileMenu(String strUserID) {
        this.userId = strUserID;
    }

    public FileMenu() {
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Information Account") || e.getActionCommand().equals("Thông tin tài khoản")) {
            InforUsers iu = new InforUsers(mainForm, true);
            iu.setVisible(true);
        }
        if (e.getActionCommand().equals("Change Password") || e.getActionCommand().equals("Đổi mật khẩu")) {
            Changepassword cp = new Changepassword(mainForm, true);
            cp.setVisible(true);
        }
        if (e.getActionCommand().equals("Log out") || e.getActionCommand().equals("Đăng xuất")) {
            MainForm.m.dispose();
            MainForm.m = new MainForm();
            MainForm.m.setVisible(true);
        }
        if (e.getActionCommand().equals("Exit") || e.getActionCommand().equals("Thoát")) {
            System.exit(0);
        }
        if (e.getActionCommand().equals("Users") || e.getActionCommand().equals("Tài khoản")) {
            Users u = new Users(mainForm, true);
            u.setVisible(true);
        }
        if (e.getActionCommand().equals("Supplier") || e.getActionCommand().equals("Nhà cung cấp")) {
            Suppliers s = new Suppliers(mainForm, true);
            s.setVisible(true);
        }
        if (e.getActionCommand().equals("Category") || e.getActionCommand().equals("Danh mục")) {
            Categories c = new Categories(mainForm, true);
            c.setVisible(true);
        }
        if (e.getActionCommand().equals("Items") || e.getActionCommand().equals("Sản phẩm")) {
            Items i = new Items(mainForm, true);
            i.setVisible(true);
        }
        if (e.getActionCommand().equals("Customer") || e.getActionCommand().equals("Khác hàng")) {
            Customer ct = new Customer(mainForm, true);
            ct.setVisible(true);
        }
        if (e.getActionCommand().equals("Create Bills") || e.getActionCommand().equals("Tạo hóa đơn")) {
            b = new Bills(mainForm, false);
            b.setUserId(userId);
            b.setVisible(true);
        }
        if (e.getActionCommand().equals("Order") || e.getActionCommand().equals("Đặt hàng")) {
            Order i = new Order(mainForm, true);
            i.setVisible(true);
        }
        if (e.getActionCommand().equals("Items End") || e.getActionCommand().equals("Sản phẩm hết hàng")) {
            Itemsend i = new Itemsend(mainForm, true);
            i.setVisible(true);
        }
        if (e.getActionCommand().equals("Order Cancel") || e.getActionCommand().equals("Hóa đơn bị hủy")) {
            OrderCancel i = new OrderCancel(mainForm, true);
            i.setVisible(true);
        }
        if (e.getActionCommand().equals("Items Returned") || e.getActionCommand().equals("Sản phẩm bị trả lại")) {
            ItemsReturned i = new ItemsReturned(mainForm, true);
            i.setVisible(true);
        }
        if (e.getActionCommand().equals("Report Chart") || e.getActionCommand().equals("Biểu đồ báo cáo")) {
            ReportChart.demo = new ReportChart("Bar Chart Demo", 0, 0);
            ReportChart.demo.pack();
            RefineryUtilities.centerFrameOnScreen(ReportChart.demo);
            ReportChart.demo.setVisible(true);
        }
        if (e.getActionCommand().equals("English")) {
            if (ChagesLanguage.languageCode.equalsIgnoreCase("en")) {
                JOptionPane.showConfirmDialog(mainForm, rb.getString("youareusingthislanguage"), rb.getString("Message"), JOptionPane.DEFAULT_OPTION);
            } else {
                ChagesLanguage.writeFileLanguageUS();
                Locale locale = new Locale(ChagesLanguage.languageCode, ChagesLanguage.countryCode);
                ResourceBundle rb = ResourceBundle.getBundle(ChagesLanguage.urlLanguage, locale);
                int option = JOptionPane.showConfirmDialog(mainForm, rb.getString("changelanguage"), rb.getString("Message"), JOptionPane.YES_NO_OPTION);
                if (option == JOptionPane.YES_OPTION) {
                    MainForm.m.dispose();
                    MainForm.m = new MainForm();
                    MainForm.m.setVisible(true);
                }
                ChagesLanguage.readFileLanguage();
            }
        }
        if (e.getActionCommand().equals("Vietnamese")) {
            if (ChagesLanguage.languageCode.equalsIgnoreCase("vi")) {
                JOptionPane.showConfirmDialog(mainForm, rb.getString("youareusingthislanguage"), rb.getString("Message"), JOptionPane.DEFAULT_OPTION);
            } else {
                ChagesLanguage.writeFileLanguageVN();
                Locale locale = new Locale(ChagesLanguage.languageCode, ChagesLanguage.countryCode);
                ResourceBundle rb = ResourceBundle.getBundle(ChagesLanguage.urlLanguage, locale);
                int option = JOptionPane.showConfirmDialog(mainForm, rb.getString("changelanguage"), rb.getString("Message"), JOptionPane.YES_NO_OPTION);
                if (option == JOptionPane.YES_OPTION) {
                    MainForm.m.dispose();
                    MainForm.m = new MainForm();
                    MainForm.m.setVisible(true);
                }
                ChagesLanguage.readFileLanguage();
            }
        }

    }
    Locale locale = new Locale(ChagesLanguage.languageCode, ChagesLanguage.countryCode);
    ResourceBundle rb = ResourceBundle.getBundle(ChagesLanguage.urlLanguage, locale);

    public JMenuBar jMenuBar(ClassLoader cl) {
        JMenuBar jmenuBar = new JMenuBar();
        FileMenu fileMenu = new FileMenu(userId);

        /**
         * Menu System
         */
        //JMenu menuSystem = new JMenu(Constant.getBundle().getString("system"));
        JMenu menuSystem = new JMenu(rb.getString("system"));
        menuSystem.setIcon(new ImageIcon("src/Images/icon-system.png"));


        // MenuItem Info
        //JMenuItem information = new JMenuItem(Constant.getBundle().getString("information"), new ImageIcon("src/Images/icon-infomation-account.png"));
        JMenuItem information = new JMenuItem(rb.getString("information"), new ImageIcon("src/Images/icon-infomation-account.png"));
        information.setMnemonic(KeyEvent.VK_I);
        information.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_I, ActionEvent.ALT_MASK));
        information.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        information.addActionListener(fileMenu);

        // MenuItem ChangePassword
        //JMenuItem changepass = new JMenuItem(Constant.getBundle().getString("changepass"), new ImageIcon("src/Images/icon-chage-password.png"));
        JMenuItem changepass = new JMenuItem(rb.getString("changepass"), new ImageIcon("src/Images/icon-chage-password.png"));
        changepass.setMnemonic(KeyEvent.VK_U);
        changepass.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_U, ActionEvent.ALT_MASK));
        changepass.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        changepass.addActionListener(fileMenu);


        // MenuItem Logout
        //JMenuItem Logout = new JMenuItem(Constant.getBundle().getString("Logout"), new ImageIcon("src/Images/icon-logout.png"));
        JMenuItem Logout = new JMenuItem(rb.getString("Logout"), new ImageIcon("src/Images/icon-logout.png"));
        Logout.setMnemonic(KeyEvent.VK_L);
        Logout.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_L, ActionEvent.ALT_MASK));
        Logout.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        Logout.addActionListener(fileMenu);


        // MenuItem Exit
        //JMenuItem exit = new JMenuItem(Constant.getBundle().getString("exit"), new ImageIcon("src/Images/icon-exit.png"));
        JMenuItem exit = new JMenuItem(rb.getString("exit"), new ImageIcon("src/Images/icon-exit.png"));
        exit.setMnemonic(KeyEvent.VK_F4);
        exit.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_F4, ActionEvent.ALT_MASK));
        exit.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        exit.addActionListener(fileMenu);


        /**
         * Menu User
         */
        //JMenu menuManager = new JMenu(Constant.getBundle().getString("manager"));
        JMenu menuManager = new JMenu(rb.getString("manager"));
        menuManager.setIcon(new ImageIcon("src/Images/icon-manager.png"));

        // MenuItem addUser
        //JMenuItem addUser = new JMenuItem(Constant.getBundle().getString("adduser"), new ImageIcon("src/Images/icon-adduser.png"));
        JMenuItem addUser = new JMenuItem(rb.getString("adduser"), new ImageIcon("src/Images/icon-adduser.png"));
        addUser.setMnemonic(KeyEvent.VK_A);
        addUser.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_A, ActionEvent.SHIFT_MASK));
        addUser.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        addUser.addActionListener(fileMenu);


        // MenuItem addSupplier
        //JMenuItem addSupplier = new JMenuItem(Constant.getBundle().getString("addsupplier"), new ImageIcon("src/Images/icon-supplier.png"));
        JMenuItem addSupplier = new JMenuItem(rb.getString("addsupplier"), new ImageIcon("src/Images/icon-supplier.png"));
        addSupplier.setMnemonic(KeyEvent.VK_N);
        addSupplier.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_N, ActionEvent.SHIFT_MASK));
        addSupplier.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        addSupplier.addActionListener(fileMenu);


        // MenuItem addCategory
        //JMenuItem addCategory = new JMenuItem(Constant.getBundle().getString("addcategory"), new ImageIcon("src/Images/icon-category.png"));
        JMenuItem addCategory = new JMenuItem(rb.getString("addcategory"), new ImageIcon("src/Images/icon-category.png"));
        addCategory.setMnemonic(KeyEvent.VK_C);
        addCategory.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_C, ActionEvent.SHIFT_MASK));
        addCategory.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        addCategory.addActionListener(fileMenu);


        // MenuItem addItem
        //JMenuItem addItem = new JMenuItem(Constant.getBundle().getString("additem"), new ImageIcon("src/Images/icon-Item.png"));
        JMenuItem addItem = new JMenuItem(rb.getString("additem"), new ImageIcon("src/Images/icon-Item.png"));
        addItem.setMnemonic(KeyEvent.VK_Y);
        addItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_Y, ActionEvent.SHIFT_MASK));
        addItem.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        addItem.addActionListener(fileMenu);


        // MenuItem addCustomer
        //JMenuItem addCustomer = new JMenuItem(Constant.getBundle().getString("addcustomer"), new ImageIcon("src/Images/icon-Customer.png"));
        JMenuItem addCustomer = new JMenuItem(rb.getString("addcustomer"), new ImageIcon("src/Images/icon-Customer.png"));
        addCustomer.setMnemonic(KeyEvent.VK_K);
        addCustomer.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_K, ActionEvent.SHIFT_MASK));
        addCustomer.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        addCustomer.addActionListener(fileMenu);
        /**
         * Bills Order
         */
        //JMenu bills = new JMenu(Constant.getBundle().getString("bills"));
        JMenu bills = new JMenu(rb.getString("bills"));
        bills.setIcon(new ImageIcon("src/Images/icon-order.png"));

        // MenuItem createBills
        //JMenuItem createBills = new JMenuItem(Constant.getBundle().getString("createbills"), new ImageIcon("src/Images/icon-createBills.png"));
        JMenuItem createBills = new JMenuItem(rb.getString("createbills"), new ImageIcon("src/Images/icon-createBills.png"));
        createBills.setMnemonic(KeyEvent.VK_O);
        createBills.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_O, ActionEvent.CTRL_MASK));
        createBills.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        createBills.addActionListener(fileMenu);


        // MenuItem order
        //JMenuItem order = new JMenuItem(Constant.getBundle().getString("order"), new ImageIcon("src/Images/icon-ordersmall.png"));
        JMenuItem order = new JMenuItem(rb.getString("order"), new ImageIcon("src/Images/icon-ordersmall.png"));
        order.setMnemonic(KeyEvent.VK_H);
        order.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_H, ActionEvent.SHIFT_MASK));
        order.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        order.addActionListener(fileMenu);



        // Menu  menuReportChart
        JMenu menuReportChart = new JMenu(rb.getString("Report"));
        menuReportChart.setIcon(new ImageIcon("src/Images/icon-report.png"));


        JMenuItem Itemsend = new JMenuItem(rb.getString("Itemsend"), new ImageIcon("src/Images/icon-Item-end.png"));
        Itemsend.setMnemonic(KeyEvent.VK_I);
        Itemsend.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_I, ActionEvent.SHIFT_MASK));
        Itemsend.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        Itemsend.addActionListener(fileMenu);

        JMenuItem OrderCancel = new JMenuItem(rb.getString("OrderCancel"), new ImageIcon("src/Images/icon-ordersmall-cancel.png"));
        OrderCancel.setMnemonic(KeyEvent.VK_O);
        OrderCancel.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_O, ActionEvent.SHIFT_MASK));
        OrderCancel.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        OrderCancel.addActionListener(fileMenu);

        JMenuItem ItemsReturned = new JMenuItem(rb.getString("ItemsReturned"), new ImageIcon("src/Images/icon-Item-returned.png"));
        ItemsReturned.setMnemonic(KeyEvent.VK_F);
        ItemsReturned.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_F, ActionEvent.SHIFT_MASK));
        ItemsReturned.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        ItemsReturned.addActionListener(fileMenu);

        JMenuItem ReportChart = new JMenuItem(rb.getString("ReportChart"), new ImageIcon("src/Images/icon-report-small.png"));
        ReportChart.setMnemonic(KeyEvent.VK_R);
        ReportChart.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_R, ActionEvent.SHIFT_MASK));
        ReportChart.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        ReportChart.addActionListener(fileMenu);


        // Menu  menuLanguage
        JMenu menuLanguage = new JMenu(rb.getString("Language"));
        menuLanguage.setIcon(new ImageIcon("src/Images/icon-language.png"));

        // MenuItem English
        JMenuItem English = new JMenuItem(Constant.getBundle().getString("English"), new ImageIcon("src/Images/icon-languageE.png"));
        English.setMnemonic(KeyEvent.VK_E);
        English.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_E, ActionEvent.SHIFT_MASK));
        English.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        English.addActionListener(fileMenu);
        menuLanguage.add(English);

        // MenuItem Vietnamese
        JMenuItem Vietnamese = new JMenuItem(Constant.getBundle().getString("Vietnamese"), new ImageIcon("src/Images/icon-languageV.png"));
        Vietnamese.setMnemonic(KeyEvent.VK_V);
        Vietnamese.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_V, ActionEvent.SHIFT_MASK));
        Vietnamese.getAccessibleContext().setAccessibleDescription(
                "This doesn't really do anything");
        Vietnamese.addActionListener(fileMenu);
        menuLanguage.add(Vietnamese);
        /*
         * 
         */



//        if (Login.referRID.equals("7")) {
//            jmenuBar.add(menuSystem);
//            menuSystem.add(information);
//            menuSystem.add(changepass);
//            menuSystem.add(Logout);
//            menuSystem.add(exit);
//
//            jmenuBar.add(menuManager);
//            menuManager.add(addUser);
//            menuManager.add(addSupplier);
//            menuManager.add(addCategory);
//            menuManager.add(addItem);
////            menuManager.add(Itemsend);
////            menuManager.add(ItemsReturned);
////            menuManager.add(addCustomer);
////
////            jmenuBar.add(bills);
////            bills.add(createBills);
////            bills.add(order);
////            bills.add(OrderCancel);
////
////
////            jmenuBar.add(menuReportChart);
////            menuReportChart.add(ReportChart);
//        }
//        if (Login.referRID.equals("8")) {
//            jmenuBar.add(menuSystem);
//            menuSystem.add(information);
//            menuSystem.add(changepass);
//            menuSystem.add(Logout);
//            menuSystem.add(exit);
//
//            jmenuBar.add(menuManager);
////            menuManager.add(addUser);
//            menuManager.add(addSupplier);
//            menuManager.add(addCategory);
//            menuManager.add(addItem);
////            menuManager.add(Itemsend);
//            menuManager.add(ItemsReturned);
//            menuManager.add(addCustomer);
//
//            jmenuBar.add(bills);
//            bills.add(createBills);
//            bills.add(order);
//            bills.add(OrderCancel);
//
//
////            jmenuBar.add(menuReportChart);
////            menuReportChart.add(ReportChart);
//        }
//        if (Login.referRID.equals("9")) {
//            jmenuBar.add(menuSystem);
//            menuSystem.add(information);
//            menuSystem.add(changepass);
//            menuSystem.add(Logout);
//            menuSystem.add(exit);
//
//            jmenuBar.add(menuManager);
////            menuManager.add(addUser);
////            menuManager.add(addSupplier);
////            menuManager.add(addCategory);
//            menuManager.add(addItem);
//            menuManager.add(Itemsend);
////            menuManager.add(ItemsReturned);
////            menuManager.add(addCustomer);
//
////            jmenuBar.add(bills);
////            bills.add(createBills);
////            bills.add(order);
////            bills.add(OrderCancel);
//
//
//            jmenuBar.add(menuReportChart);
//            menuReportChart.add(ReportChart);
//        }
//        if (Login.referRID.equals("10")) {
//            jmenuBar.add(menuSystem);
//            menuSystem.add(information);
//            menuSystem.add(changepass);
//            menuSystem.add(Logout);
//            menuSystem.add(exit);
//
//            jmenuBar.add(menuManager);
////            menuManager.add(addUser);
////            menuManager.add(addSupplier);
////            menuManager.add(addCategory);
////            menuManager.add(addItem);
////            menuManager.add(Itemsend);
//            menuManager.add(ItemsReturned);
////            menuManager.add(addCustomer);
//
//            jmenuBar.add(bills);
////            bills.add(createBills);
//            bills.add(order);
//            bills.add(OrderCancel);
//
//
//            jmenuBar.add(menuReportChart);
//            menuReportChart.add(ReportChart);
//        }

        jmenuBar.add(menuSystem);
        menuSystem.add(information);
        menuSystem.add(changepass);
        menuSystem.add(Logout);
        menuSystem.add(exit);

        jmenuBar.add(menuManager);
        menuManager.add(addUser);
        menuManager.add(addSupplier);
        menuManager.add(addCategory);
        menuManager.add(addItem);
        menuManager.add(Itemsend);
        menuManager.add(ItemsReturned);
        menuManager.add(addCustomer);

        jmenuBar.add(bills);
        bills.add(createBills);
        bills.add(order);
        bills.add(OrderCancel);


        jmenuBar.add(menuReportChart);
        menuReportChart.add(ReportChart);

        jmenuBar.add(menuLanguage);

        return jmenuBar;
    }
}
